<?php 
if(KT!='KhiThe') exit;
class homeNews_controller extends homeNews_model
{
	public function __construct()
	{	
		global $lang;
		
		$lang['url_base'] = url_base;	
		$this->path_cur = dirname(__FILE__);	
		parent::__construct();
		parent::addObject('khithe_template');
		parent::addObject('khithe_request');
		parent::addObject('khithe_string');
		parent::addObject('khithe_images');
		
		$this->lang = $lang;
	}

	public function index_ajax(){
	
		$str = $this->index($this->valUrl(2),1);
		return $str;
	}

	public function index($page=1,$load_ajax=Null)
	{
		$resultHtml = '';
		$strNews = '';
		$limit = 4;
		$intStr = 500;
		$this->lang['p'] = $page;
		$strModule = parent::khithe_display_template(dirname(__FILE__).'/homeNews');
		$arrBlockHtml = $this->khithe_getBlockHtml($strModule);
		
		$arrnew = parent::get_news($page,$limit);
		if($arrnew>0){
			foreach ($arrnew as $row_News) 
			{				
				if($row_News['Picture'])
				{					
					$fileImg = path_base.'/uploads/news/'.$row_News['Picture'];			
					$fileThumbImg = path_base.'/uploads/news/cache/'.$row_News['Picture'];
					if(!is_file($fileThumbImg) && is_file($fileImg))
					{
						$this->setIMG($fileImg);
						$this->resizeImage(200, 180, 'auto');
						$this->saveImage($fileThumbImg);
					}
				}
				
				$logo = $this->getLogo($row_News['FullContents'],$row_News['ID']);
				$logo = ($row_News['Picture']?url_base.'uploads/news/cache/'.$row_News['Picture']:$logo);
				$logo = $logo?$logo:'';
				$strLogo ='';
				if($logo){
					$strLogo ='<a href="'.url_base.($this->seo_list_parent(categorys,NULL,$row_News['CategoryID'])).$row_News['SeoKey'].'.html">		
						<img class="lazy logo_News" src="'.$logo.'" />
					</a>';
				}
				$resultHtml .= $this->khithe_assign($arrBlockHtml['new'], array(
					'url_new'=>url_base.($this->seo_list_parent(categorys,NULL,$row_News['CategoryID'])).$row_News['SeoKey'].'.html',
					'title_new'=> $row_News["Title"],
					'View'=> $row_News["View"],
					'PostDate_new'=>date("d-m-Y h:m:s",$row_News["PostDate"]),
					'logo_new'=>$strLogo,
					'content_new'=>$this->strShort($row_News["FullContents"],$intStr),
				));					
			}
			
			if(!empty($load_ajax))
			{
				return parent::khithe_assign($resultHtml, $this->lang);
			}
			
			$resultHtml = $this->khithe_assignBlock($strModule, array('htmlnew'=>$resultHtml));
		}
		$this->lang['content-News'] = $strNews;
		
		return $strModule = parent::khithe_assign($resultHtml, $this->lang);
	}
	


}
?>